<%-- 
    Document   : userManager
    Created on : 2016-6-30, 19:42:14
    Author     : cxhd
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../../link.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <!--<script type="text/javascript" src="${base}/appjs/registerListModule.js" ></script>-->
    </head>
    <style>
        .am-table>tbody>tr>td{
            padding-top: 4px;
            padding-bottom: 4px;

        }
    </style>
    <body ng-app="userManage" ng-controller="mainCtrl">

        <div class="am-cf am-padding am-padding-bottom-0">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理列表</strong> / <small>User list</small></div>
        </div>
        <!--        <hr>-->
        <div class="am-g">
            <div class="am-u-sm-12 ">
                <div class="am-panel am-panel-default" style="overflow: hidden">
                    <div class="am-panel-bd">
                        <div class="am-g">
                            <div class="am-u-sm-6 am-u-md-6">
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <button type="button" class="am-btn am-btn-default" ng-click="addUser()"><span class="am-icon-plus">新用户</span> </button>
                                    </div>
                                </div>
                            </div>

                            <div class="am-u-sm-6 am-u-md-3">
                                <div class="am-input-group am-input-group-sm">
                                    <input type="text" class="am-form-field">
                                    <span class="am-input-group-btn">
                                        <button class="am-btn am-btn-default" type="button">搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <div class="am-g">
                            <table class="am-table am-table-striped  am-table-bordered  am-table-hover ">
                                <thead>
                                    <tr>
                                        <th class="table-id">用户ID</th>
                                        <th class="table-title">用户名字</th>
                                        <th class="table-type">性别</th>
                                        <th class="table-author am-hide-sm-only">生日</th>
                                        <th class="table-date am-hide-sm-only">部门</th>
                                        <th class="table-set">操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr ng-repeat="list in userlists" ng-click='selectPatient(list)'  >

                                        <td>{{list.user_id}}</td>
                                        <td>{{list.name}}</</td>
                                        <td>{{list.sex}}</td>
                                        <td class="am-hide-sm-only">{{list.birth}}</td>
                                        <td class="am-hide-sm-only">{{list.department}}</td>
                                        <td>
                                            <div class="am-btn-toolbar">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    <button ng-click="deleteUser(list)" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 删除</button>
<!--                                                    <button ng-click="updateU(list)" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 修改</button>
                                                    <button type="button" ng-click="getEmr()" class="am-btn am-btn-primary" data-am-modal="{target: '#my-prompt', closeViaDimmer:0, width:700,height:800}"><span class="am-icon-pencil-square-o"></span>修改2</button>-->
                                                    <button type="button" class="btn btn-primary"  ng-click="updateUser(list)">
                                                            <!--data-target=".bs-example-modal-lg"-->
                                                            修改3</button>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>

                                </tbody>
                            </table>
                            <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data.currentPage" items-per-page="data.pageSize" total-items="data.bigTotalItems" ng-model="data.bigCurrentPage" max-size="data.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                        </div>
                    </div>
                </div>
          </div>
        </div>
        <div>
            <!--<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button>-->

<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="myModal">
    <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="deteleInfo()"><span aria-hidden="true">&times;</span></button>
        <h3 class="modal-title" id="myModalLabel" style="text-align:center ;">{{title}}用户</h3>
      </div>
      <div class="modal-body">
         <table>
                        <tr>
                            <td>用户ID:<input type="text" style="font-size: 16px;font-weight:bold; width: 80px" ng-model="user_id"></td>
                            <td>用户名字:<input type="text" style="font-size: 16px;font-weight:bold;width: 80px" ng-model="name"></td>
                            <td>生日:
                                <input type="text"  style="font-size: 8px;font-weight:bold;width: 120px" ng-model="birth">格式：<label style="font">2016-01-01</label>
                                <!--<input type="date" ng-model="birth"  data-am-datepicker="{format: 'yyyy-mm-dd', viewMode: 'years'}" readonly required/>-->
                            </td>
                        </tr>
                        <tr>  
                            <td>密码:<input type="password" style="font-size: 16px;font-weight:bold;width: 80px" ng-model="password"></td>
                            <td>手机号:<input type="text"  style="font-size: 16px;font-weight:bold;width: 80px" ng-model="phone"></td>
                            <td><input type="radio" style="font-size: 16px;font-weight:bold;width: 30px" name="sex" id="nan" value="1" class="xb"  checked ><label for="nan">男</label>
                                <input type="radio" style="font-size: 16px;font-weight:bold;width: 30px" name="sex" value="2"  class="xb" id="nv"><label for="nv">女</label></td>
                        </tr>
                        <tr>
                            <td>部门:<input type="text" style="font-size: 16px;font-weight:bold;width: 80px" ng-model="department"></td>
                            <td>医生/护士:<input type="text" style="font-size: 16px;font-weight:bold;width: 80px" ng-model="position"></td>
                            <td>地址:<input type="text" style="font-size: 16px;font-weight:bold;width: 80px" ng-model="address"></td>
                        </tr>
                        <tr> <td colspan="3">备注：<textarea style=" width: 500px;height:20px "  ng-model="data1"></textarea></td></tr>
                         <tr> <td colspan="3">备注：<textarea style=" width: 500px;height:20px "  ng-model="data2"></textarea></td></tr>
                          <tr> <td colspan="3">备注：<textarea style=" width: 500px;height:20px "  ng-model="data3"></textarea></td></tr>
                    </table>
      </div>
      <div class="modal-footer" style="text-align:center ;">
          <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="deteleInfo()">取消</button>
        <button type="button" class="btn btn-primary" ng-click="saveUserInfo()" >保存</button>
        
      </div>
    </div>
  </div>

  </div>
</div>

</body>
</html>
<script>
   angular.module("userManage",[])
            .controller("mainCtrl", function ($scope) {
                
         $scope.getUsers= function(){//显示用户信息
             $.post("userList/getUserList",function(data){
                 console.log(data);
                 if(data){
                $scope.userlists=data;
                for(var tmp in $scope.userlists){
                    if($scope.userlists[tmp].sex==1){
                        $scope.userlists[tmp].sex='男';
                    }else{
                        $scope.userlists[tmp].sex='女';
                    }
                }
                $scope.$apply();
            }
             })
         } 
          $scope.getUsers();//显示用户
          
          $scope.addUser=function(){//打开新增窗口
                  $scope.title="新增";
             $('#myModal').modal({
        show:true,
        backdrop:true
        })
          }
          $scope.updateUser=function(tmp){//打开修改窗口
               $scope.title="修改";
               $scope.pk=tmp.pk;
               $scope.name=tmp.name;
                $scope.user_id=tmp.user_id;
                 $scope.birth=tmp.birth;
                  $scope.address=tmp.address; 
                  $scope.phone=tmp.phone;
                   $scope.sex=tmp.sex;
                  $scope.password=tmp.password;
                   if($scope.sex=='男'){
                       $("#nan").attr("checked",true);
                   }else{
                        $("#nv").attr("checked",true);
                   }
                   $scope.department=tmp.department;
                   $scope.position=tmp.position;
                   $scope.data1=tmp.data1;
                   $scope.data2=tmp.data2;
                   $scope.data3=tmp.data3;
             
             $('#myModal').modal({
        show:true,
        backdrop:true
        })
          }
          $scope.pk="";
          $scope.saveUserInfo=function(){
                    //密码不能为空
                    if($scope.password==""){
                        alert("密码不能为空");
                        return;
                    }   
              // 检验用户名是否可用
              $.post("userList/getLisUserReP",{name:$scope.name,pk:$scope.pk},function(data){
                  console.log(data);
                  if(data=='true'){
                      alert("该用户名已经存在,请重新输入");
                      return;
                  }
              //检验生日输入格式是否正确
        
              if($scope.pk!=""){              
                 
                      var sex= $(".xb:checked").val();          
                     alert( $(".xb:checked").val());                
                   $.post("userList/updateUser",{pk:$scope.pk,user_id:$scope.user_id,name:$scope.name,birth:$scope.birth,
                      address:$scope.address, phone:$scope.phone, sex:sex, department:$scope.department,
                      position:$scope.position,data1:$scope.data1,data2:$scope.data2,data3:$scope.data3,password:$scope.password},function(data){
                      if(data=='true'){
                         alert("修改成功！");
                      }
                       $scope.deteleInfo();
                           $scope.getUsers();
                  })
              
              }else{
                    alert($scope.pk);
                 var sex= $(".xb:checked").val();          
                $.post("userList/addUser",{user_id:$scope.user_id,name:$scope.name,birth:$scope.birth,
                      address:$scope.address, phone:$scope.phone, sex:sex, department:$scope.department,
                      position:$scope.position,data1:$scope.data1,data2:$scope.data2,data3:$scope.data3,password:$scope.password},function(data){
                      if(data=='true'){
                         alert("新增成功！");
                      }
                       $scope.deteleInfo();
                      $scope.getUsers();
                  }) 
          }
         
          $("#myModal").modal("hide");
           
//             $scope.$apply();
       
         })
          }
          $scope.deleteUser=function(list){
              var gnl=confirm("你真的确定要删除吗?"); //友好提示
                if (gnl==true){ 
               $.post("userList/deleteUser",{pk:list.pk},function(data){
                  if(data=='true'){
                      alert("删除成功！",1000);
                       $scope.getUsers();
                  }
              })
              } else{ 
                return; 
                } 
              
          }
          $scope.deteleInfo=function(){
             $scope.pk="";
               $scope.name="";
                $scope.user_id="";
                 $scope.birth="";
                  $scope.address=""; 
                  $scope.phone="";
                   $scope.sex="";
                       $("#nan").attr("checked",true);
                   $scope.department="";
                   $scope.position="";
                   $scope.data1="";
                   $scope.data2="";
                   $scope.data3="";
                   $scope.password="";
          }
          //注意每当模态框关闭或保存后  要清理原有的数据
//          $scope.saveUserInfo=function(){
//              if($scope.pk!=""){//修改操作
//                   $.post("",{},function(){
//                      
//                  })
//              }else{//保存操作
//                  $.post("",{},function(){
//                      
//                  })
//              }
//          }
    });
</script>
